package org.lonetree.tc.webapp.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public abstract class AdminAction extends SecureAction {

	@Override
	protected final ActionForward executeSecure(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		if(getCurrentUser().isAdmin()){
			//execute the admin action
			return executeAdmin(mapping, form, request, response);
		}
		else{
			//user is not authorized
			return mapping.findForward("unauthorizedPage"); //TODO create global forward for unauthorizedPage
		}
	}

	protected abstract ActionForward executeAdmin(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception;

}
